<!-- 搜索表单 -->
<template>
  <el-form label-width="100px"
           class="ele-form-search"
           @keyup.enter.native="search"
           @submit.native.prevent>
    <el-row :gutter="15">
      <el-col :lg="6"
              :md="12">
        <el-form-item label="跳转链接:">
          <el-input clearable
                    v-model="where.name"
                    placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :lg="6"
              :md="12">
        <el-form-item label="轮播图类型:">
          <el-select v-model="where.coupon_type">
            <el-option label="所有"
                       value=""></el-option>
            <el-option label="小程序"
                       value="1"></el-option>
            <el-option label="公众号"
                       value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :lg="6"
              :md="12">
        <el-form-item label="跳转类型:">
          <el-select v-model="where.coupon_type">
            <el-option label="所有"
                       value=""></el-option>
            <el-option label="外部调转类型"
                       value="1"></el-option>
            <el-option label="内部调整类型"
                       value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :lg="6"
              :md="12">
        <div class="ele-form-actions">
          <el-button type="primary"
                     icon="el-icon-search"
                     class="ele-btn-icon"
                     @click="search">
            查询
          </el-button>
          <el-button @click="reset">重置</el-button>
        </div>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
const DEFAULT_WHERE = {
  money: ''
};

export default {
  name: 'RoleSearch',
  data () {
    return {
      // 表单数据
      where: { ...DEFAULT_WHERE },

      dateRange: [],
      // 日期时间选择器快捷项
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick (picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '最近一个月',
            onClick (picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '最近三个月',
            onClick (picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }
        ]
      }
    };
  },
  methods: {
    /* 搜索 */
    search () {
      const [d1, d2] = this.dateRange ?? [];
      this.$emit('search', {
        ...this.where,
        start_time: d1 ? d1 : '',
        end_time: d2 ? d2 : ''
      });
    },
    /*  重置 */
    reset () {
      this.where = { ...DEFAULT_WHERE };
      this.dateRange = [];
      this.search();
    }
  }
};
</script>
